package servlet;

import bean.Result;
import com.google.gson.Gson;
import dao.CartDao;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "RemoveCardServlet", value = "/RemoveCardServlet.s")
public class
RemoveCardServlet extends HttpServlet {

    private CartDao dao = new CartDao();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        final String carid = request.getParameter("carid");

        Result result = null;
        int res = dao.removeCard(carid);
        if (res == 1){
            result = new Result(1,"删除成功!",null);
        } else {
            result = new Result(0,"删除失败!",null);
        }
        final String json = new Gson().toJson(result);
        response.getWriter().append(json);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
